import React, { Component, lazy } from 'react';
import { BrowserRouter, HashRouter, Switch, Route, Redirect} from 'react-router-dom';
import {createBrowserHistory} from 'history'
import Live from '@/views/live'; //首页组件


import getComponent from '@/components/getComponent';

const history = createBrowserHistory();
// const Live=lazy(()=>import('@/views/live')) //路由懒加载

const routes = [
	{ path: '/',
		exact: true,
		component: Live
	},
	{ path: '/test',
		exact: false,
		component: (props) => getComponent(props, () => import('@/views/login'))
	},
	// { path: '/topic/:id',
	// 	exact: false,
	// 	component: (props) => getComponent(props, () => import('../Component/Topic'))
	// },

];
/**
 * (路由根目录组件，显示当前符合条件的组件)
 * 
 * @class Roots
 * @extends {Component}
 */
// class Roots extends Component {
//     render() {
//         return (
//             <div>{this.props.children}</div>
//         );
//     }
// }
// var history = process.env.NODE_ENV !== 'production' ? browserHistory : hashHistory;
const supportsHistory = 'pushState' in window.history;
let Router = process.env.NODE_ENV !== 'production' ? BrowserRouter : HashRouter;
const RouteConfig = (
    <Router  history={history}>
	    <Switch>
	      {/*<Route path="/" exact component={IndexList} />*/}
		    {routes.map((route, index) => (
			    <Route
				    key={index}
				    path={route.path}
				    exact={route.exact}
				    component={route.component}
			    />
		    ))}
		    <Redirect from='' to="/" />
	    </Switch>
    </Router>
);

export default RouteConfig;